package com.dengke.hellospringmvc.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class OldLoginInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.out.println("\n--------OldLoginInterceptor.perHandle-----");
		System.out.println("Request URL:"+request.getRequestURL());
		System.out.println("Sorry! This URL is no longer uesed,Redirect to /admin/login");
		//redirect重定向
		response.sendRedirect(request.getContextPath()+"/admin/login");
		//不在像后面执行
		return false;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		//This code will never be run.
		System.out.println("\n-------OldLoginInterceptor.postHandle-----");
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		//This code will never be run.
		System.out.println("\n---------OldLoginInterptor.afterCompletion-------");
	}

}
